// #define quickread
#ifdef quickread
#include <cstdio>
template<typename T>
inline void read(T &x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1, c=getchar();}
    while('0'<=c||c<='9')
    x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template<typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else
#include <iostream>
#endif
#define DEBUG
#include <algorithm>
using namespace std;
using ll=long long;
const int N=5e5+10, MOD=998244353;
ll n, q, a[N], sum[N], sums[N];

void init()
{
    // read(n), read(q);
    cin >> n >> q;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=n; i>=1; i--) sum[i]=(sum[i]+sum[i+1]+a[i])%MOD;
    for(int i=n; i>=1; i--) sums[i]=(sums[i+1]+sum[i])%MOD;

    // printf("sum []:");
    // for(int i=1; i<=n; i++) printf("%lld ", sum[i]);
    // puts("");
    // printf("sums[]:");
    // for(int i=1; i<=n; i++) printf("%lld ", sums[i]);
    // puts("");
}

void solve()
{
    init();
    for(int i=1; i<=q; i++)
    {
        int l, r; cin >> l >> r; //read(l), read(r);
        cout << (((sums[l]-sums[r+1])%MOD-(r-l+1)*sum[r+1])%MOD +MOD)%MOD << endl;
    }
}

signed main()
{
    #ifdef DEBUG
        freopen("./in.txt", "r", stdin);
        // freopen("./out.txt", "w", stdout);
    #endif 
    #ifndef quickread
        // ios::sync_with_stdio(0);
        // cin.tie(0); cout.tie(0);
    #endif
    int T=1; // scanf("%d", &T);
    while(T--)
    {
        solve();
    }
    return 0;
}

